package com.zmx.patients.adapter;

import android.app.Activity;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.google.android.flexbox.AlignItems;
import com.google.android.flexbox.FlexDirection;
import com.google.android.flexbox.FlexWrap;
import com.google.android.flexbox.FlexboxLayoutManager;
import com.google.android.flexbox.JustifyContent;
import com.wang.adapters.adapter.BaseAdapterRvList;
import com.wang.adapters.base.BaseViewHolder;
import com.wang.adapters.interfaceabstract.OnItemClickListener;
import com.zmx.patients.R;
import com.zmx.patients.pojo.InterrogationResult;
import com.zmx.patients.view.activity.AllDoctorActivity;
import com.zmx.patients.view.activity.DiseaseIntroducedActivity;
import com.zmx.patients.view.activity.TitleMessageActivity;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 程序猿：胖胖祥
 * 时 间：2020/11/11  23:31
 * 功 能：
 */
public class InterrogationResultsAdapter extends BaseAdapterRvList<InterrogationResultsAdapter.ViewHolder, InterrogationResult> {

    private InterrogationResultsStringAdapter adapter;
    private InterogationMessageAdapter m_adapter;

    public InterrogationResultsAdapter(Activity activity) {
        super(activity);
    }

    @Override
    protected void onBindVH(ViewHolder holder, int listPosition, InterrogationResult interrogationResult) {

        holder.zz_text.setText(interrogationResult.getDisease());
        holder.ms_text.setText("你有"+interrogationResult.getKeyword().size()+"种症状比较符合"+interrogationResult.getDisease());

        adapter = new InterrogationResultsStringAdapter(mActivity);
        //设置LayoutManager
        FlexboxLayoutManager flexboxLayoutManager = new FlexboxLayoutManager(mActivity);
        //主轴为水平方向，起点在左端
        flexboxLayoutManager.setFlexDirection(FlexDirection.ROW);
        //按正常方向换行
        flexboxLayoutManager.setFlexWrap(FlexWrap.WRAP);
        //定义项目在副轴轴上如何对齐
        flexboxLayoutManager.setAlignItems(AlignItems.CENTER);
        //多个轴对齐方式
        flexboxLayoutManager.setJustifyContent(JustifyContent.FLEX_START);
        holder.recyclerView.setLayoutManager(flexboxLayoutManager);
        holder.recyclerView.setAdapter(adapter);
        adapter.setListAndNotifyDataSetChanged(interrogationResult.getKeyword());

        m_adapter = new InterogationMessageAdapter(mActivity);
        holder.r_View.setLayoutManager(new LinearLayoutManager(mActivity));
        holder.r_View.setAdapter(m_adapter);
        if (interrogationResult.getLis() != null){

            m_adapter.setListAndNotifyDataSetChanged(interrogationResult.getLis());
            m_adapter.setOnItemClickListener(new OnItemClickListener() {
                @Override
                protected void onItemClick(View view, int listPosition) {

                    Intent intent = new Intent();
                    intent.putExtra("id",interrogationResult.getLis().get(listPosition).getId());
                    intent.setClass(mActivity, TitleMessageActivity.class);
                    mActivity.startActivity(intent);
                }
            });

        }



        holder.ms_class.setText("就诊科室："+interrogationResult.getClass_name());

        holder.button_a.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                Intent intent = new Intent();
                intent.putExtra("name",interrogationResult.getDisease());
                intent.putExtra("logo",1);
                intent.setClass(mActivity, DiseaseIntroducedActivity.class);
                mActivity.startActivity(intent);

            }
        });
        holder.button_b.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                Intent intent = new Intent();
                intent.setClass(mActivity, AllDoctorActivity.class);
                mActivity.startActivity(intent);

            }
        });
        holder.button_c.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                Intent intent = new Intent();
                intent.putExtra("name",interrogationResult.getDisease());
                intent.putExtra("logo",2);
                intent.setClass(mActivity, DiseaseIntroducedActivity.class);
                mActivity.startActivity(intent);

            }
        });

    }


    @NonNull
    @Override
    protected InterrogationResultsAdapter.ViewHolder onCreateVH(ViewGroup parent, LayoutInflater inflater) {

        InterrogationResultsAdapter.ViewHolder holder = new InterrogationResultsAdapter.ViewHolder(inflater.inflate(R.layout.adapter_interrogation_results, parent, false));
        return holder;
    }

    static class ViewHolder extends BaseViewHolder {

        @BindView(R.id.ms_text)
        TextView ms_text;
        @BindView(R.id.zz_text)
        TextView zz_text;
        @BindView(R.id.ms_class)
        TextView ms_class;
        @BindView(R.id.recyclerView)
        RecyclerView recyclerView;
        @BindView(R.id.r_View)
        RecyclerView r_View;
        @BindView(R.id.button_a)
        Button button_a;
        @BindView(R.id.button_b)
        Button button_b;
        @BindView(R.id.button_c)
        Button button_c;

        ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }

    }

}
